import LocalStorage from "../../engine/LocalStorage";
import { Logger } from "../../engine/Logger";

export default class SettingModel {

    public static instance: SettingModel = new SettingModel();

    public static Local_Key: string = "SettingModel";

    public musicVolumn: number = 1; //音乐
    public soundVolum: number = 1; //音效
    public effect: number = 1;
    public vibrate: number = 1;//震动


    public init() {
        let str: string = LocalStorage.getItem(SettingModel.Local_Key);
        if (str) {
            try {
                let obj: object = JSON.parse(str);
                SettingModel.instance.musicVolumn = obj["musicVolumn"]
                SettingModel.instance.soundVolum = obj["soundVolum"]
                SettingModel.instance.effect = obj["effect"] || 0
                SettingModel.instance.vibrate = obj["vibrate"]
                // Logger.log("SettingModel==", SettingModel.instance)
            } catch (error) {
                SettingModel.instance.saveToLocal();
            }
        }
    }

    public saveToLocal() {
        LocalStorage.setItem(SettingModel.Local_Key, JSON.stringify(SettingModel.instance))
    }
}
